package com.hec.yygh.user.controller.admin;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hec.yygh.common.result.R;
import com.hec.yygh.model.user.UserInfo;
import com.hec.yygh.user.service.UserInfoService;
import com.hec.yygh.vo.user.UserInfoQueryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/admin/userinfo")
public class UserController {

    @Autowired
    private UserInfoService userInfoService;

    //用户列表（条件查询带分页）
    @GetMapping("{page}/{limit}")
    public R list(@PathVariable Long page,
                  @PathVariable Long limit,
                  UserInfoQueryVo userInfoQueryVo) {
        Page<UserInfo> pageModel = userInfoService.selectUserInfoPage(page,limit,userInfoQueryVo);
        return R.ok().data("pageModel",pageModel);
    }

    @GetMapping("/lock/{userId}/{status}")
    public R lock(@PathVariable("userId") Long userId,
                  @PathVariable("status") Integer status){
        userInfoService.lock(userId,status);
        return R.ok();
    }

    @GetMapping("/show/{id}")
    public R show(@PathVariable("id") Long id){
        Map<String,Object> map = userInfoService.show(id);
        return R.ok().data(map);
    }

    @GetMapping("/approval/{id}/{authStatus}")
    public R approval(@PathVariable("id") Long id,
                  @PathVariable("authStatus") Integer authStatus){
        userInfoService.approval(id,authStatus);
        return R.ok();
    }

}
